package com.lonely.web.controller.order;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.api.R;
import com.lonely.order.domain.dto.secondprocess.*;
import com.lonely.order.domain.vo.secondprocess.QueryOrderSecondProcessPageQueryVO;
import com.lonely.order.service.IOrderSecondProcessService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author : 黄志标
 * @date: 2025/8/6 14:42
 * @description: 订单二次工艺请求处理器
 */
@RestController
@RequestMapping("/orderManager/orderSecondProcess")
public class OrderSecondProcessController {

    @Autowired
    private IOrderSecondProcessService orderSecondProcessService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<Page<QueryOrderSecondProcessPageQueryVO>> page(@RequestBody QueryOrderSecondProcessPageQueryDTO queryDto) {
        return R.data(this.orderSecondProcessService.page(queryDto));
    }


    /**
     * 统计指定查询条件下的各个状态的数量
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/getStatusTotals")
    public R<Map<Integer, Integer>> getStatusTotals(@RequestBody QueryOrderSecondProcessPageQueryDTO queryDto) {
        return R.data(this.orderSecondProcessService.getStatusTotals(queryDto));
    }

    /**
     * 二次工艺确认
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/confirmSecondProcess")
    @SaCheckPermission("production:orderSecondProcess:confirmSecondProcess")
    public R<Boolean> confirmSecondProcess(@RequestBody @Validated ConfirmSecondProcessDTO requestDto) {
        this.orderSecondProcessService.confirmSecondProcess(requestDto);
        return R.status(true);
    }

    /**
     * 修改裁片二次工艺
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/updateCuttingSecondProcess")
    @SaCheckPermission("production:orderSecondProcess:updateCuttingSecondProcess")
    public R<Boolean> updateCuttingSecondProcess(@RequestBody @Validated UpdateCuttingSecondProcessDTO requestDto) {
        this.orderSecondProcessService.updateCuttingSecondProcess(requestDto);
        return R.status(true);
    }

    /**
     * 工艺发起
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/processInitiation")
    @SaCheckPermission("production:orderSecondProcess:processInitiation")
    public R<Boolean> processInitiation(@RequestBody @Validated ProcessInitiationDTO requestDto) {
        this.orderSecondProcessService.processInitiation(requestDto);
        return R.status(true);
    }


    /**
     * 工艺回料
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/processRecycledMaterial")
    @SaCheckPermission("production:orderSecondProcess:processRecycledMaterial")
    public R<Boolean> processRecycledMaterial(@RequestBody @Validated ProcessRecycledMaterialDTO requestDto) {
        this.orderSecondProcessService.processRecycledMaterial(requestDto);
        return R.status(true);
    }

    /**
     * 获取默认的发料数量
     *
     * @param produceOrderId
     * @return
     */
    @GetMapping("/getDefaultRecycledMaterialsQuantity/{produceOrderId}")
    public R<Integer> getDefaultRecycledMaterialsQuantity(@PathVariable("produceOrderId") Long produceOrderId) {
        return R.data(this.orderSecondProcessService.getDefaultRecycledMaterialsQuantity(produceOrderId));
    }


}
